/**
 * 
 */
package io.gitee.falllee.dao.generator;

import java.sql.Time;
import java.sql.Types;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;

/**
 * @author batty
 *
 */
public class DaoJavaTypeResolver extends JavaTypeResolverDefaultImpl {
    public DaoJavaTypeResolver() {
        super();
        super.typeMap.put(Types.TINYINT,
            new JdbcTypeInformation("TINYINT", new FullyQualifiedJavaType(Integer.class.getName())));
        super.typeMap.put(Types.SMALLINT,
            new JdbcTypeInformation("SMALLINT", new FullyQualifiedJavaType(Integer.class.getName())));
        super.typeMap.put(Types.TIME, new JdbcTypeInformation("TIME", //$NON-NLS-1$
            new FullyQualifiedJavaType(Time.class.getName())));
    }
    
    @Override
    protected FullyQualifiedJavaType calculateBigDecimalReplacement(IntrospectedColumn column, FullyQualifiedJavaType defaultType) {
        FullyQualifiedJavaType answer;
        
        if (column.getScale() > 0 || column.getLength() > 18 || forceBigDecimals) {
            answer = defaultType;
        } else if (column.getLength() > 9) {
            answer = new FullyQualifiedJavaType(Long.class.getName());
        } else {
            answer = new FullyQualifiedJavaType(Integer.class.getName());
        }
        
        return answer;
    }
}
